package com.baitai.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baitai.common.utils.SecurityUtils;
import com.baitai.system.domain.vo.SysUserPrizesVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baitai.common.annotation.Log;
import com.baitai.common.core.controller.BaseController;
import com.baitai.common.core.domain.AjaxResult;
import com.baitai.common.enums.BusinessType;
import com.baitai.system.domain.SysUserPrizes;
import com.baitai.system.service.ISysUserPrizesService;
import com.baitai.common.utils.poi.ExcelUtil;
import com.baitai.common.core.page.TableDataInfo;

/**
 * 用户奖品Controller
 * 
 * @author xx
 * @date 2024-07-21
 */
@RestController
@RequestMapping("/system/sysUserPrizes")
public class SysUserPrizesController extends BaseController
{
    @Autowired
    private ISysUserPrizesService sysUserPrizesService;

    /**
     * 查询用户奖品列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysUserPrizes:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserPrizes sysUserPrizes)
    {
        startPage();
        List<SysUserPrizes> list = sysUserPrizesService.selectSysUserPrizesList(sysUserPrizes);
        return getDataTable(list);
    }

    /**
     * 导出用户奖品列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysUserPrizes:export')")
    @Log(title = "用户奖品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserPrizes sysUserPrizes)
    {
        List<SysUserPrizes> list = sysUserPrizesService.selectSysUserPrizesList(sysUserPrizes);
        ExcelUtil<SysUserPrizes> util = new ExcelUtil<SysUserPrizes>(SysUserPrizes.class);
        util.exportExcel(response, list, "用户奖品数据");
    }

    /**
     * 获取用户奖品详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sysUserPrizes:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysUserPrizesService.selectSysUserPrizesById(id));
    }

    /**
     * 新增用户奖品
     */
    @PreAuthorize("@ss.hasPermi('system:sysUserPrizes:add')")
    @Log(title = "用户奖品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserPrizes sysUserPrizes)
    {
        return toAjax(sysUserPrizesService.insertSysUserPrizes(sysUserPrizes));
    }

    /**
     * 修改用户奖品
     */
    @PreAuthorize("@ss.hasPermi('system:sysUserPrizes:edit')")
    @Log(title = "用户奖品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserPrizes sysUserPrizes)
    {
        return toAjax(sysUserPrizesService.updateSysUserPrizes(sysUserPrizes));
    }

    /**
     * 删除用户奖品
     */
    @PreAuthorize("@ss.hasPermi('system:sysUserPrizes:remove')")
    @Log(title = "用户奖品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysUserPrizesService.deleteSysUserPrizesByIds(ids));
    }


    /**
     * 查询用户奖品列表
     */
    @GetMapping("/appList")
    public AjaxResult appList()
    {
        startPage();
        SysUserPrizes sysUserPrizes = new SysUserPrizes();
        sysUserPrizes.setUserId(SecurityUtils.getUserId());
        List<SysUserPrizesVo> list = sysUserPrizesService.selectSysUserPrizesVoList(sysUserPrizes);
        return AjaxResult.success(getDataTable(list));
    }

    /**
     * 查询用户奖品列表
     */
    @GetMapping("/superiorAndSubordinateList")
    public TableDataInfo superiorAndSubordinateList(SysUserPrizes sysUserPrizes)
    {
        startPage();
        List<SysUserPrizes> list = sysUserPrizesService.selectSysUserPrizesList(sysUserPrizes);
        return getDataTable(list);
    }

}
